package com.it.test7;

public class GirlFriendTest {
    public static void main(String[] args) {
        //1.定义数组存入女朋友的对象
        GirlFriend[] arr=new GirlFriend[4];
        //2.创建女朋友的对象
        GirlFriend gf1=new GirlFriend("小李",18,'女',"画画");
        GirlFriend gf2=new GirlFriend("婧祎",19,'女',"唱歌");
        GirlFriend gf3=new GirlFriend("祎祎",20,'女',"读书");
        GirlFriend gf4=new GirlFriend("小祎",21,'女',"运动");
        //3.把对象添加到数组中
        arr[0]=gf1;
        arr[1]=gf2;
        arr[2]=gf3;
        arr[3]=gf4;
        //4.求和
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            //i表示索引 arr[i]元素(女朋友对象)
            GirlFriend gf=arr[i];
            //累加
            sum=sum+ gf.getAge();
        }
        //5.平均值
        int avg=sum/arr.length;
        //6.统计年龄比平均值低的有几个,打印他们的信息
        int count=0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf=arr[i];
            if(gf.getAge()<avg){
                count++;
                System.out.println(gf.getName()+","+gf.getAge()+","+gf.getGender()+","+gf.getHobby());
            }
        }
        System.out.println(count+"个");
    }
}
